# coding:utf-8
# 王一舟
# demo_2_对比数值的过滤.py
from deepdiff import DeepDiff

json_1 = {
    "goods_id": "9",
    "spec": [{"type": "颜色", "value": "粉色"}, {"type": "尺码", "value": "L"}],
}
json_2 = {
    "goods_id": "9",
    "spec": [{"type": "颜色", "value": "粉色"}, {"type": "尺码", "value": "L"}],
}
print(DeepDiff(json_1, json_2))


#todo 序列容器,排序改变
l1 = [1,2,3]
l2 = [3,2,1]
print(DeepDiff(l1, l2))
#{'values_changed': {'root[0]': {'new_value': 3, 'old_value': 1}, 'root[2]': {'new_value': 1, 'old_value': 3}}}


'''
过滤条件
忽略排序 ignore_order=True , 默认Flase
忽略大小写 ignore_string_case=True 默认Flase
忽略对比某个数据,exclude_paths={集合},{}内写数据的key,或路径
'''

#todo 1 忽略排序 ignore_order=True , 默认Flase
l1 = [1,2,3]
l2 = [3,2,1]
print(DeepDiff(l1, l2,ignore_order=True)) #参数ignore_order=True,忽略数据的排序
#返回{}

#todo 2 忽略大小写 ignore_string_case=True 默认Flase
json_1 = {
    "GOODS_ID": "9",
}
json_2 = {
    "goods_id": "9",
}
print(DeepDiff(json_1,json_2,ignore_string_case=True)) #参数

#todo 3 忽略对比某个数据,exclude_paths={集合},{}内写数据的key,或路径
json_1 = {
    "goods_id": 11,
    "spec": [{"type": "颜色", "value": "粉色"}, {"type": "尺码", "value": "L"}],
}
json_2 = {
    "goods_id": "9",
    "spec": [{"type": "颜色", "value": "黑色"}, {"type": "尺码", "value": "L"}],
}
print(DeepDiff(json_1,json_2,exclude_paths={"goods_id","root['spec'][0]"})) #参数
#exclude_paths={}的{}中写入要忽略对比的key或者数据的路径, 注意必须是外""内''的形式 如:"root['spec'][0]"，多个数据以逗号分隔





